//void, Obj This

Unit this;
int i, time;

Sleep(1720+rand(GetConst("RandTimeStart"))+GetConst("AddTimeStart"));
this = This.AsUnit;

while(!.IsValid) Sleep(10000); 
time = 19000;
while(.IsAlive){

	if(IsAIPlayer(.player)){
		while(.IsValid) {
			Sleep(60000);
			if(!IsAIPlayer(.player)) break;
		}
		
	} else {
		if(!.InHolder){
			if(.IsVisible){
				Sleep(3000+rand(120));
				
				i = time+rand(1000);
				if(.TimeWithoutAttack >= i)
					if(!.EnemiesInSight())
						.SetVisible(false);
				
			} else {
				Sleep(10011+rand(1000));
				if(time > 9000)
					if(EnvReadString(.player, "Camouflage") == "researched")
						time = 9000;
			}
		} else {
			Sleep(5011+rand(1000));
		}
	}
}

//prevent behavior script from terminating (this will lockup the game)
while(true) Sleep(50000);
